package com.tjsinfo.tjsoa.common;



import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ValidateSessionTag extends TagSupport {

		private String name = "user";
	    private String page = "/nopopedom.jsp";
	    private Log log =LogFactory.getLog(this.getClass().getName());

	    public int doEndTag() throws JspException {
		boolean valid = false;
		HttpSession session = pageContext.getSession();
		//判断session中是否有用户信息存在
		if ((session.getAttribute(name) != null) )
		    valid = true;

		if (valid)
		    return (EVAL_PAGE);		//如果用户存在则不做任何处理
		else {
		    try {
			pageContext.forward(page);	//用户不存在则跳转到指定的页面
		    } catch (Exception e) {
			throw new JspException(e.toString());
		    }
		    return (SKIP_PAGE);	//执行跳转
		}
	    }
	    public int doStartTag() throws JspException {
		return (SKIP_BODY);
	    }
	    public String getName() {
		return (this.name);
	    }
	    public String getPage() {
		return (this.page);
	    }
	    public void release() {
	        super.release();
	        this.name = "sessiontype";
	        this.page = "/nopopedom.jsp";
	    }
	    public void setName(String name) {
		this.name = name;
	    }
	    public void setPage(String page) {
		this.page = page;
	    }
	}
